<?php

include 'config.php';

class Module_Control {
    /* 建立连接 */

    function getConnection() {
        $link = new mysqli($GLOBALS['mydbhost'], $GLOBALS['mydbuser'], $GLOBALS['mydbpw'], $GLOBALS['mydbname']);
        return $link;
    }

    /* 查询院系信息 */

    function findDepartMent() {
        $link = $this->getConnection();
        $sql = "select * from xb";
        $result = $link->query($sql);
        $results = array();
        while ($row = mysqli_fetch_assoc($result)) {
            $results[] = $row;
        }
        return $results;
    }

    /* 根据院系查询专业 */

    function findMajorByDeptId($deptId) {
        $link = $this->getConnection();
        $sql = "select * from zy where xbdm='" . $deptId . "'";
        $result = $link->query($sql);
        $results = array();
        while ($row = mysqli_fetch_assoc($result)) {
            $results[] = $row;
        }
        return $results;
    }

    /* 根据专业查询班级 */

    function findClassByMarjorId($marjorId) {
        $link = $this->getConnection();
        $sql = "select * from bj where zydm='" . $marjorId . "'";
        $result = $link->query($sql);
        $results = array();
        while ($row = mysqli_fetch_assoc($result)) {
            $results[] = $row;
        }
        return $results;
    }

    /* 根据班级信息查询学生 */

    function findStudentInfoByClassId($classId) {
        $link = $this->getConnection();
        $sql = "select count(*) as count from xs where bjdm='" . $classId . "'";
        $result = $link->query($sql);
        $rs = mysqli_fetch_assoc($result);
        $data['count'] = $rs['count'];
        $sql = "SELECT xh as full_xh,RIGHT(xh,2) as xh,xm from xs where bjdm='" . $classId . "'";
        $result = $link->query($sql);
        $results = array();
        while ($row = mysqli_fetch_assoc($result)) {
            $results[] = $row;
        }
        $data['info'] = $results;
        return $data;
    }

    /* 保存考勤信息 */

    function save($xbdm, $xbmc, $zydm, $zymc, $bjdm, $bjmc, $ydrs, $sdrs, $qxqk) {
        $link = $this->getConnection();
        $stmt = $link->prepare("INSERT INTO tj (xbdm,xbmc,zydm,zymc,bjdm,bjmc,ydrs,sdrs,qxqk,tjrq) VALUES (?,?,?,?,?,?,?,?,?,CURDATE())");
        $stmt->bind_param("isisisiis", $xbdm, $xbmc, $zydm, $zymc, $bjdm, $bjmc, $ydrs, $sdrs, $qxqk);
        $stmt->execute();
        $result = ["success"];
        return $result;
    }

    /* 按年度分院系统计出勤 */

    function yxcqByYear() {
        return $data;
    }

    /* 按年度分专业统计出勤 */

    function zycqByYear() {
        return $data;
    }

}
?>

